package com.kwz.common.ui.components.initializers;

import java.awt.Component;
import javax.swing.JTextPane;
import javax.swing.text.Document;
import com.kwz.common.IContext;
import com.kwz.common.designpatterns.ExceptionManager;
import com.kwz.common.designpatterns.factory.BadContextException;
import com.kwz.common.ui.components.IUiComponentContextInitializer;


/**
 * <p>
 * 		Initialiseur par defaut pour JTextPane
 * </p> 
 *
 * @author mbi
 */
public class UiDefaultJTextPaneInitializer extends UiDefaultJEditorPaneInitializer {

    /**
     * 
     */
    public UiDefaultJTextPaneInitializer() {
        super();
        
    }

    /* (non-Javadoc)
     * @see com.kwz.common.ui.components.IUiComponentInitializer#init(java.awt.Component, com.kwz.common.IContext)
     */
    public void init(Component component, IContext ctx) throws BadContextException {
        try{
            super.init(component, ctx);
            
	        //Initialisation de l'objet Document
	        if(ctx.containsKey(UI_INIT_TEXT_DOCUMENT)){
	            ((JTextPane)component).setDocument((Document)ctx.getObjectProperty(UI_INIT_TEXT_DOCUMENT));	            
	        }
	        	        	        
        }catch(Exception ce){
            ExceptionManager.processExceptionNotThrow(this, ce);
        }

    }

    /* (non-Javadoc)
     * @see com.kwz.common.ui.components.IUiComponentInitializer#getDefaultInitializerContext()
     */
    public IContext getDefaultInitializerContext() {
        return getDefaultInitializerContext(getContextInitializer());
    } 
        
    /* (non-Javadoc)
     * @see com.kwz.common.ui.components.IUiComponentInitializer#getDefaultInitializerContext(com.kwz.common.ui.components.IUiComponentContextInitializer)
     */
    public IContext getDefaultInitializerContext(IUiComponentContextInitializer contextInitializer) {
        IContext context = super.getDefaultInitializerContext();
        context.putProperty(UI_INIT_TEXT_DOCUMENT, contextInitializer.getContextValueFor(UI_JTEXTPANE, UI_INIT_TEXT_DOCUMENT));                
        return context;
    }
}
